class FindpassController {
    constructor($rootScope, $scope, $state, $cookieStore, $timeout, ngDialog, dialogService, UserService){
        
        var vm = this;

        vm.$rootScope    = $rootScope;
        vm.$state 	   = $state;
        vm.$cookieStore  = $cookieStore;
        vm.$timeout 	   = $timeout;
        vm.ngDialog 	   = ngDialog;
        vm.dialogService = dialogService;
        vm.UserService   = UserService;

        $rootScope.loadingText = true;
        
        // 初始化表单数据
        vm.user = {
            username: ''
        }

    }

    // 提交表单
    submitForm(isValid) {

        var vm = this;
        
        // 验证失败
        if (!isValid) {
            vm.dialogService.error('用户名错误');
        }

        // 验证成功
        if (isValid) {

            // 禁用按钮
            vm.hide = true;

            // 忘记密码
            vm.UserService.postFindpass({cellphone: vm.user.username})
            .then(data => {

                // 显示按钮
                vm.hide = false;

                // 提示用户
                if (data.code==0) {
                    vm.ngDialog.open({
                        template: '<p>密码已重置，请查收短信</p>',
                        className: 'ngdialog-theme-default ngdialog-alert ngdialog-success',
                        plain: true
                    });
                }

                console.log(data)
            }, error => {
                console.log('error')
            })
        }

        return false;
    }
}

FindpassController.$inject = ['$rootScope', '$scope', '$state', '$cookieStore', '$timeout', 'ngDialog', 'dialogService', 'UserService']; 

export default FindpassController;